#ifndef _MAKEXE_H_
#define _MAKEXE_H_

#include <stdio.h>

#include "sr.h"
#include "eds.h"
#include "edl.h"
#include "edb_type.h"

#define ST_MKE_NULL		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 0)
#define ST_MKE_EPE_DECL		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 1)
#define ST_MKE_EDE_DECL		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 2)
#define ST_MKE_ETT_DEF		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 3)
#define ST_MKE_ET_NAME		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 4)

#define ST_MKE_EDEXPR		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 5)
#define ST_MKE_REACTORS		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 6)

#define ST_MKE_MENU		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 10)
#define ST_MKE_MENUGROUP	SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 11)

#define ST_MKE_CLASS		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 15)
#define ST_MKE_CONTEXT		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 16)
#define ST_MKE_CTXCLS_NAME	SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 17)

#define ST_MKE_ETT		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 20)
#define ST_MKE_LITERAL		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 21)
#define ST_MKE_NAMED_LITERAL	SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 22)
#define ST_MKE_ASRV		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 23)
#define ST_MKE_ASRTV		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 24)
#define ST_MKE_ET_DESC		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 25)
#define ST_MKE_UICLS_DESC	SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 26)

#define ST_MKE_TREE_PATH	SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 27)
#define ST_MKE_ATTR		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 28)

#define ST_MKE_EMBED		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 29)
#define ST_MKE_FUNCSIG		SR_BUILD_TYPE(SR_TYPECLS_DIR, SR_CUSTOM | 30)

typedef enum {
	FUNC_MODIFIER_AUTONOMOUS = 0x1,
	FUNC_MODIFIER_OVERWRITE = 0x2,
} func_modifier_t;

extern int	mkelineno;
extern const char	*specdir;
extern const char	*specsrc;

extern ECMBOOL	install_mode;
extern ECMBOOL	dryrun_mode;
extern char	*inst_clxhome;

void mkeerror(char *);
int yylex(void);
void mke_input(char *buf, int *result, int max);

ECM_INLINE ECMBOOL is_EPE_decl(const sr_t *sr_decl);
ECM_INLINE ECMBOOL is_EDE_decl(const sr_t *sr_decl);
sr_t *create_sr_ETT(ecm_uint32 lineno, const char *name, ECMBOOL is_HMS, ECMBOOL is_ref, sr_t *sr_supers);

void check_ETT_desc(ecm_uint32, sr_t *sr_ETT);

void add_super_ETTs(ecm_uint32 lineno, sr_t *sr_ETT, sr_t *sr_ETTs_super);
sr_t *add_super_ETT(ecm_uint32 lineno, sr_t *sr_ETTs, sr_t *sr_ETT);

sr_t *create_EPE_decl(ecm_uint32 lineno, sr_t *sr_ETT, sr_t *sr_extra, ECMBOOL overwrite);
sr_t *create_EDE_decl(ecm_uint32 lineno, sr_t *sr_ETT, sr_t *sr_def_block, sr_t *sr_exts, ECMBOOL overwrite);

sr_t *create_function(ecm_uint32 lineno, func_modifier_t modifiers, sr_t *sr_ETT, char *funcname, sr_t *sr_args, sr_t *sr_mke_edexpr);
sr_t *add_function(ecm_uint32 lineno, sr_t *sr_funcs, sr_t *sr_func);
func_modifier_t add_func_modifier(ecm_uint32 lineno,
				  func_modifier_t modifiers,
				  func_modifier_t modifier);
sr_t *create_ientry(ecm_uint32 lineno, sr_t *sr_tree_path, sr_t *sr_def);
sr_t *add_ientry(ecm_uint32 lineno, sr_t *sr_ientries, sr_t *sr_ientry);

sr_t *find_decl(sr_t *sr_decls, const char *ETT_name);
ECM_INLINE ECMBOOL sr_ETT_to_srt(sr_t *sr_ett, srt_t *psrt);
sr_t *add_entity_decl(ecm_uint32 lineno, sr_t *sr_entities, sr_t *sr_decl);
sr_t *adjust_entity_decls(sr_t *sr_entities);

sr_t *create_asrv(ecm_uint32 lineno, char *asrv);
sr_t *create_attr(ecm_uint32 lineno, srt_t srt, sr_t *sr_asrv);
sr_t *add_ext(sr_t *sr_exts, const char *type, sr_t *sr_ext);
sr_t *create_tree_path(ecm_uint32 lineno, char *path);
sr_t *create_entity_name(ecm_uint32 lineno, char *name);
sr_t *create_entity_def(ecm_uint32 lineno, sr_t *sr_ET_name, sr_t *sr_ETT, sr_t *sr_asrv, sr_t *sr_def_block, sr_t *sr_exts, ECMBOOL overwrite);
void add_entity_def(sr_t *sr_defs, sr_t *sr_def);

sr_t *create_sr_mke_edexpr(ecm_uint32 lineno, char *edexpr);

sr_t *build_ctx_def(char *ctxname, char *sr_literals_vars);
sr_t *create_context(ecm_uint32 lineno, char *ctxname, char *ctxclass, sr_t *sr_ctx_val, sr_t *sr_mke_edexpr);
sr_t *build_embed(ecm_uint32, char *name, char *path);
sr_t *build_active_area(ecm_uint32 lineno, char *name, sr_t *sr_asrtv);
void add_embed(ecm_uint32 lineno, sr_t *sr_mke_embdes, sr_t *sr_mke_embed);
sr_t *build_binded_UI(const char *modname, sr_t *sr_sobj, void *handle);
sr_t *build_binded_MENU(sr_t *sr_sobj);
ECMBOOL build_binded_AREA(sr_t *sr_sobj, sr_t **psr_smod_AREA);

sr_t *create_context_class(ecm_uint32 lineno, char *clsname, sr_t *sr_decl);

sr_t *create_class_decl(void);
void add_class_decl(ecm_uint32 lineno, sr_t *sr_decl, sr_t *sr_list_stmt);

void add_context_class(ecm_uint32 lineno, sr_t *sr_classes, sr_t *sr_class);
ECMBOOL add_context(ecm_uint32 lineno, sr_t *sr_context_set, sr_t *sr_context);
void add_context_set(ecm_uint32 lineno, sr_t *sr_context_sets, sr_t *sr_context_set);

sr_t *add_context_value(ecm_uint32 lineno, sr_t *sr_ctxval, sr_t *sr_list_stmt);

extern srt_t bdexpr_get_srt_with_srt(srt_t srt, const sr_t *sr_LNP);

sr_t *add_section(ecm_uint32 lineno, const char *desc, const char *name,
		  sr_t *sr_sections, sr_t *sr_section);

#endif
